#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>

int main(int argc, char *argv[]) {

	if (argc == 1) {
		std::cout << "Usage " << argv[0] << " " << "FILE..." << std::endl;
		std::cout << "This program gives correct sort of [tests].csv" << std::endl;
	}
	std::vector<int> array;
	std::ifstream input;
	input.open(argv[1]);
	if (input.fail()) {
		std::cerr << "File " << argv[1] << "not found!" << std::endl;
		exit(EXIT_FAILURE);
	}

	while (input.good()) {
		char number[20];
		input.getline(number, 20,',');
		array.push_back(atoi(number));
	}
	input.close();
	std::sort(array.begin(), array.end());

	std::ofstream output;
	output.open("toutput.csv", std::ofstream::out);
	for (std::vector<int>::iterator it = array.begin(); it != array.end(); ++it) {
		if ((it + 1) == array.end())
			output << *it;
		else 
			output << *it << ",";
	}
}
